package game;

import javax.swing.*;
import java.awt.*;

/** 整个窗口世界 */
public class World extends JPanel{//JPanel面板--


    Battleship ship=new Battleship();
    public void paint(Graphics g) {
        //要用Battleship类中的成员变量
        //用ship.shipImg得到了一个图片对象
        ship.shipImg.paintIcon(null,g,ship.x,30);
        //表示Battleship中的  Icon类型的成员变量
        //ship.成员变量的名字
        System.out.println("paint()"+ship.x);
    }

    public void start() {
        for(;;){
            repaint();//不断调用paint()
            ship.x=ship.x+1;
            //改变Battleship的x坐标
            try {
                Thread.sleep(400);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {
        JFrame frame=new JFrame();//new JFrame()创建一个窗口对象
        World world=new World();//自动执行paint()方法//new World()创建了一个面板对象
        frame.add(world);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(641+16,479+39);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        world.start();


        /*
        SeaObject[] submarine=new SeaObject[6];
        submarine[0]=new TorpedoSubmarine();
        submarine[1]=new TorpedoSubmarine();
        submarine[2]=new ObserveSubmarine();
        submarine[3]=new ObserveSubmarine();
        submarine[4]=new MineSubmarine();
        submarine[5]=new MineSubmarine();
        for (int i=0;i<submarine.length;i++){
            SeaObject s=submarine[i];
            System.out.println(s.x+","+s.y+","+s.speed);
            s.move();
        }

         */
        }



    }



















